package org.mspring.mlog.web.module.web.forums;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.mlog.entity.bbs.ForumCatalog;
import org.mspring.mlog.service.bbs.ForumCatalogService;
import org.mspring.mlog.service.bbs.ForumService;
import org.mspring.mlog.web.security.action.ActionSecurity;
import org.mspring.mlog.web.security.action.rule.rules.AccessForumRule;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 
 * @author Gao Youbo
 * @since 2013年8月8日
 */
@Widget
@RequestMapping("/forums")
public class BBS_IndexWidget extends BBS_AbstractWidget {
    @Autowired
    private ForumService forumService;
    @Autowired
    private ForumCatalogService forumCatalogService;

    @RequestMapping({ "/", "" })
    @ActionSecurity(rules = AccessForumRule.class)
    public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
        List<ForumCatalog> forumCatalogs = forumCatalogService.getAll();
        // for (ForumCatalog forumCatalog : forumCatalogs) {
        // forumCatalog.setForums(forumService.getForumByCatalog(forumCatalog.getId()));
        // }
        model.addAttribute("forumCatalogs", forumCatalogs);
        return "skin:/forums/index";
    }
}